/**
 * 
 */
package cc.rico.redis.pub;

import org.junit.Before;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.data.redis.core.RedisTemplate;

/**
 * 
 * @author rico 2016年7月4日
 *
 */
public class PublishMessageUtil {
	private static final Logger logger  = LoggerFactory.getLogger(PublishMessageUtil.class);
	
	private RedisTemplate<String, String> redisTemplate;
	
	@SuppressWarnings("unchecked")
	@Before
	public void init() {
		ApplicationContext context = new ClassPathXmlApplicationContext("classpath:spring-redis.xml");
		redisTemplate = (RedisTemplate<String, String>) context.getBean("redisTemplate");
	}
	
	@Test
	public void pubMessage() {
		String channel = "chat";
		String message = "redis message...";
		redisTemplate.convertAndSend(channel, message);
		
		try {
			Thread.sleep(10 * 1000);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
	}

}
